/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bean;

import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;

public class DataBaseConnection {

    private String nama ;
    private String ttl ;
    private String alamat ;
    private String notlp ;
    private String noktp ;
    private String nosim ;
    private String tglsewa ;
    
    private String mobil ;
    
    private String namamobil ;
    private String jenismobil ;
    private String platnomor ;
    private String pemilik ;
    
    private String nomor ;
    private String nama2 ;
    private String alamat2 ;
    private String tglkembali ;

    private static Connection conn;

// Sesuaikan properti jdbcURL dengan basis data anda
    private String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:XE";
    String userid = "system";
    String password = "hr";

    /** Creates a new instance of UserConnection */
    public DataBaseConnection() {
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            conn = ds.getConnection(userid, password);
            System.out.println("Koneksi berhasil");
        } catch (SQLException ex) {
            System.out.println("Masih belum koneksi");
        }
    }
    

    public DataBaseConnection(String nama, String ttl, String alamat, String notlp, String noktp, String nosim,
            String tglsewa, String lamasewa,
            String namamobil, String jenismobil, String platnomor, String pemilik){
        this.nama = nama;
        this.ttl = ttl;
        this.alamat = alamat;
        this.notlp = notlp;
        this.noktp = noktp;
        this.nosim = nosim;
        this.tglsewa = tglsewa;
        
        this.namamobil = namamobil;
        this.jenismobil = jenismobil;
        this.platnomor = platnomor;
        this.pemilik = pemilik;
    }

    public boolean isConnected(){
        if (conn!=null) {
            return true;
        }
        else {
            return false;
        }
    }
    public boolean getClosed(){
        if(isConnected()){
            try {
                conn.close();
                conn=null;
            } catch (SQLException ex) {
            }
            return true;
        } else {
            return false;
        }
    }

    public String getJdbcUrl() {
        return jdbcUrl;
    }

    public void setJdbcUrl(String jdbcUrl) {
        this.jdbcUrl = jdbcUrl;
    }   

    public Connection getConnection() {
        return conn;
    }

    public void setConn(Connection connection) {
        DataBaseConnection.conn = connection;
    }

    public static void main(String args[]){
        DataBaseConnection conn = new DataBaseConnection();

        try{
            String query="select * from customer";
            Statement statement = conn.getConnection().createStatement();
            ResultSet result = statement.executeQuery(query);

            while (result.next()){
                System.out.println("Nama : "+result.getString("nama"));
                System.out.println("TTL  : "+result.getString("ttl"));
                System.out.println("Alamat : "+result.getString("alamat"));
                System.out.println("No Tlp : "+result.getString("notlp"));
                System.out.println("No Ktp  : "+result.getString("noktp"));
                System.out.println("No Sim : "+result.getString("nosim"));
                System.out.println("Tgl sewa  : "+result.getString("tglsewa"));
                System.out.println("Lama sewa : "+result.getString("lamasewa"));
            }
            statement.close();
        } catch(Exception ex){
            System.out.println("message: "+ex.getMessage());
        }

    }

    /**
     * @return the nama
     */
    public String getNama() {
        return nama;
    }

    /**
     * @param nama the nama to set
     */
    public void setNama(String nama) {
        this.nama = nama;
    }

    /**
     * @return the ttl
     */
    public String getTtl() {
        return ttl;
    }

    /**
     * @param ttl the ttl to set
     */
    public void setTtl(String ttl) {
        this.ttl = ttl;
    }

    /**
     * @return the alamat
     */
    public String getAlamat() {
        return alamat;
    }

    /**
     * @param alamat the alamat to set
     */
    public void setAlamat(String alamat) {
        this.alamat = alamat;
    }

    /**
     * @return the notlp
     */
    public String getNotlp() {
        return notlp;
    }

    /**
     * @param notlp the notlp to set
     */
    public void setNotlp(String notlp) {
        this.notlp = notlp;
    }

    /**
     * @return the noktp
     */
    public String getNoktp() {
        return noktp;
    }

    /**
     * @param noktp the noktp to set
     */
    public void setNoktp(String noktp) {
        this.noktp = noktp;
    }

    /**
     * @return the nosim
     */
    public String getNosim() {
        return nosim;
    }

    /**
     * @param nosim the nosim to set
     */
    public void setNosim(String nosim) {
        this.nosim = nosim;
    }

    /**
     * @return the namamobil
     */
    public String getNamamobil() {
        return namamobil;
    }

    /**
     * @param namamobil the namamobil to set
     */
    public void setNamamobil(String namamobil) {
        this.namamobil = namamobil;
    }

    /**
     * @return the jenismobil
     */
    public String getJenismobil() {
        return jenismobil;
    }

    /**
     * @param jenismobil the jenismobil to set
     */
    public void setJenismobil(String jenismobil) {
        this.jenismobil = jenismobil;
    }

    /**
     * @return the platnomor
     */
    public String getPlatnomor() {
        return platnomor;
    }

    /**
     * @param platnomor the platnomor to set
     */
    public void setPlatnomor(String platnomor) {
        this.platnomor = platnomor;
    }

    /**
     * @return the pemilik
     */
    public String getPemilik() {
        return pemilik;
    }

    /**
     * @param pemilik the pemilik to set
     */
    public void setPemilik(String pemilik) {
        this.pemilik = pemilik;
    }

    /**
     * @return the tglsewa
     */
    public String getTglsewa() {
        return tglsewa;
    }

    /**
     * @param tglsewa the tglsewa to set
     */
    public void setTglsewa(String tglsewa) {
        this.tglsewa = tglsewa;
    }

   

    /**
     * @return the nomor
     */
    public String getNomor() {
        return nomor;
    }

    /**
     * @param nomor the nomor to set
     */
    public void setNomor(String nomor) {
        this.nomor = nomor;
    }

    /**
     * @return the nama2
     */
    public String getNama2() {
        return nama2;
    }

    /**
     * @param nama2 the nama2 to set
     */
    public void setNama2(String nama2) {
        this.nama2 = nama2;
    }

    /**
     * @return the alamat2
     */
    public String getAlamat2() {
        return alamat2;
    }

    /**
     * @param alamat2 the alamat2 to set
     */
    public void setAlamat2(String alamat2) {
        this.alamat2 = alamat2;
    }

    /**
     * @return the tglkembali
     */
    public String getTglkembali() {
        return tglkembali;
    }

    /**
     * @param tglkembali the tglkembali to set
     */
    public void setTglkembali(String tglkembali) {
        this.tglkembali = tglkembali;
    }

    /**
     * @return the mobil
     */
    public String getMobil() {
        return mobil;
    }

    /**
     * @param mobil the mobil to set
     */
    public void setMobil(String mobil) {
        this.mobil = mobil;
    }

}



